import {request} from 'umi';
import {modulesUrl} from "@/assets/constant/modulesUrl";
import {DataEntity} from "@/assets/entity/base";
import {getApiPrefix} from "@/assets/utils/utils";

/**
 * sql执行
 * @param params
 */
export async function executeSql(tableConfigId:string, params?: DataEntity) {
  console.log(params)
  return request(getApiPrefix(modulesUrl.reportReport) + "/executeSql", {
    method: 'POST',
    data:{
      ...params,
      tableConfigId:tableConfigId,
    }
  });
}

/**
 * 增加查看次数
 * @param id
 */
export async function addSeeNumber(id?:string) {
  return request(getApiPrefix(modulesUrl.reportReport) + "/addSeeNumber", {
    params:{
      id:id
    }
  });
}

/**
 * 导出
 * @param id
 */
export async function exportFile(tableConfigId:string, params?: DataEntity) {
  // 把参数做成一个map数组
  let paramMapList = [];
  paramMapList.push({key: "tableConfigId", value: tableConfigId})
  for(let key in params){
    paramMapList.push({key: key, value: params[key]})
  }
  return request(getApiPrefix(modulesUrl.reportReport) + "/export", {
    method: 'POST',
    data:{
      ...params,
      tableConfigId:tableConfigId,
    }
  });
}

